
/**************************************************************************/
/**                  JAVA SCRIPT DO SISTEMA                         **/
/**************************************************************************/


/** TRATAR COMPONENTES CALENDAR PRIME FACES **/
PrimeFaces.locales['pt'] = {
    closeText: 'OK',
    prevText: 'Anterior',
    nextText: 'Pr�ximo',
    currentText: 'Atual',
    monthNames: ['Janeiro','Fevereiro','Mar\u00e7o','Abril','Maio','Junho','Julho','Agosto','Setembro','Outubro','Novembro','Dezembro'],
    monthNamesShort: ['Jan','Fev','Mar','Abr','Mai','Jun', 'Jul','Ago','Set','Out','Nov','Dez'],
    dayNames: ['Domingo','Segunda','Ter\u00e7a','Quarta','Quinta','Sexta','S\u00e1bado'],
    dayNamesShort: ['Dom','Seg','Ter','Qua','Qui','Sex','S\u00e1b'],
    dayNamesMin: ['D','S','T','Q','Q','S','S'],
    weekHeader: 'Semana',
    firstDay: 0,
    isRTL: false,
    showMonthAfterYear: false,
    yearSuffix: '',
    timeOnlyTitle: 'S\u00f3 Horas',
    timeText: 'Hor\u00e1rio',
    hourText: 'Hora',
    minuteText: 'Minuto',
    secondText: 'Segundo',
    ampm: false,
    month: 'M\u00eas',
    week: 'Semana',
    day: 'Dia',
    allDayText : 'Todo o Dia'
};

PrimeFaces.widget.DataTable.prototype.toggleCheckAll = function() {
    var checkboxes = $(this.jqId + ' tbody.ui-datatable-data:first > tr > td.ui-selection-column').find('.ui-chkbox > .ui-chkbox-box:not(.ui-state-disabled)'),
        checked = this.checkAllToggler.hasClass('ui-state-active'),
        _self = this;

    if(checked) {
        this.checkAllToggler.removeClass('ui-state-active').children('span.ui-chkbox-icon').removeClass('ui-icon ui-icon-check');

        checkboxes.each(function() {
            _self.unselectRowWithCheckbox($(this), true);
        });
        this.fireRowUnselectEvent('');
    }
    else {
        this.checkAllToggler.addClass('ui-state-active').children('span.ui-chkbox-icon').addClass('ui-icon ui-icon-check');

        checkboxes.each(function() {
            _self.selectRowWithCheckbox($(this), true);

        });
        this.fireRowSelectEvent('');
    }

    //save state
    this.writeSelections();
};




/** MARCARA DATA PARA COMPONENTE CALENDAR PRIME FACES **/
function mascaraData(campoData){
    var data = campoData.value;
    
    if (data.length == 2){
    	campoData.value = campoData.value + '/';
        return true;              
    }
    if (data.length == 5){
    	campoData.value  = campoData.value  + '/';
        return true;
    }
    
}


/** MASCARA DECIMAL **/
function mascaraDecimal(objTextBox, SeparadorMilesimo, SeparadorDecimal, e){ 
	
    var key = '';    
    var i = j = 0;    
    var len = len2 = 0;    
    var strCheck = '0123456789';    
    var aux = aux2 = '';    
    var whichCode = (window.Event) ? e.which : e.keyCode;    
    if (whichCode == 13 || whichCode == 8) return true;    
    key = String.fromCharCode(whichCode); // Valor para o c�digo da Chave    
    if (strCheck.indexOf(key) == -1) return false; // Chave inv�lida    
    len = objTextBox.value.length;  
    if (len > 15) return false;
    for(i = 0; i < len; i++)    
        if ((objTextBox.value.charAt(i) != '0') && (objTextBox.value.charAt(i) != SeparadorDecimal)) break;    
    aux = '';    
    for(; i < len; i++)    
        if (strCheck.indexOf(objTextBox.value.charAt(i))!=-1) aux += objTextBox.value.charAt(i);    
    aux += key;    
    len = aux.length;    
    if (len == 0) objTextBox.value = '';    
    if (len == 1) objTextBox.value = '0'+ SeparadorDecimal + '0' + aux;    
    if (len == 2) objTextBox.value = '0'+ SeparadorDecimal + aux;    
    if (len > 2) {    
        aux2 = '';    
        for (j = 0, i = len - 3; i >= 0; i--) {    
            if (j == 3) {    
                aux2 += SeparadorMilesimo;    
                j = 0;    
            }    
            aux2 += aux.charAt(i);    
            j++;    
        }    
        objTextBox.value = '';    
        len2 = aux2.length;    
        for (i = len2 - 1; i >= 0; i--)    
        objTextBox.value += aux2.charAt(i);    
        objTextBox.value += SeparadorDecimal + aux.substr(len - 2, len);    
    }    
    return false;    
}    

/** MASCARA INTEIROS **/
function mascaraInteger(value){  
    
	 var tecla=(window.event)?event.keyCode:e.which;
	    if((tecla > 47 && tecla < 58)) 
	    	return true;
	    else{
	    if (tecla != 8) return false;
	        else return true;
	    }
}  

/** MASCARA HORA **/
function mascaraHora(value){
	
    if(event.keyCode<48 || event.keyCode>57){
      event.returnValue=false;
     }
    
    if(value.value.length==2 ){
   	value.value+=":";
    }
    
}

/** LIMPAR CAMPO AO SELECIONAR **/
function clearOnSelect(obj){
	obj.value = "";   
}

/** CONVERTE PARA MAINUSCULO **/
function toUpperCase(obj){
	obj.value = obj.value.toUpperCase();
}

/** CONVERTE PARA MINUSCULO **/
function toLowerCase(obj){
	obj.value = obj.value.toLowerCase();
}

